#include "definitions.h"

using namespace CGAL;
using namespace std;

triangleList CGTriangulate::m_triangles;

CGTriangulate::CGTriangulate(void)
{
}

CGTriangulate::~CGTriangulate(void)
{
}

void CGTriangulate::Triangulate()
{ 
  Point p[3];
  int i = 0;

  Finite_face_iterator ffi;
  Face_iterator fc;
   ffi = m_cgalTriangulation.faces_begin();
  while (ffi != m_cgalTriangulation.faces_end()) 
  {
    if(!m_cgalTriangulation.is_infinite(ffi))
    {
      for(i = 0 ; i < 3 ; i++)
      {
        p[i] = ffi->vertex(i)->point();
      }
      AddTriangle(p);
    }
    ++ffi;
  }
  //I got a faces from triangulation
}


void CGTriangulate::AddCCWPoint(const figureVertice & v)
{
  m_cgalTriangulation.insert(Point(v.x,v.y));
}


void CGTriangulate::AddTriangle(const Point * p)
{
  int i = 0;
  Triangle  tr;
  figureVertice v[3];
  for(i = 0;i < 3; i++)
  {
    v[i].x = p[i].x();
    v[i].y = p[i].y();
  }
  tr.SetSides(v);
  m_triangles.push_back(tr);
}


double  CGTriangulate::GetFigureField()
{
  double f;
  mpf_init2(m_field,320);
  mpf_set_d(m_field,0.0f);

  return f;
}


void CGTriangulate::Draw(const HWND & hwnd, const POINT & shift)
{
  triangleIterator it;

  for(it = m_triangles.begin();
      it != m_triangles.end();
      it ++)
  {
    (*it).Draw(hwnd, shift);
  }
}

void CGTriangulate::Clear()
{
  m_triangles.clear();
  m_cgalTriangulation.clear();
}
